package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.DefaultTypeEnum;
import com.xbongbong.paas.enums.DefaultValueEnum;
import com.xbongbong.paas.help.FormDataFormExplainHelper;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.ForbiddenSettingEnum;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ProductionOrderEnum;
import com.xbongbong.saas.enums.dictionary.ProductionOrderStatusEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import com.xbongbong.sys.enums.RoleEnum;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import lombok.Getter;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/16 20:25
 * @since v1.0
 */
@Getter
public enum TempProductionOrderEnum {
    //刷脚本专用枚举
    BASE_INFO(ProductionOrderEnum.BASE_INFO),
    SHEET_NO(ProductionOrderEnum.SHEET_NO),
    BOM_ID(ProductionOrderEnum.BOM_ID),
    BOM_VERSION(ProductionOrderEnum.BOM_VERSION),
    PLAN_TIME(ProductionOrderEnum.PLAN_TIME),
    MEMO(ProductionOrderEnum.MEMO),
    INTO_WAREHOUSE_ID(ProductionOrderEnum.INTO_WAREHOUSE_ID),
    PRODUCT(ProductionOrderEnum.PRODUCT),
    OUT_WAREHOUSE_ID(ProductionOrderEnum.OUT_WAREHOUSE_ID),
    MATERIEL(ProductionOrderEnum.MATERIEL),
    OWNER_ID(ProductionOrderEnum.OWNER_ID),
    COUSERID(ProductionOrderEnum.COUSERID),

    SYSTEM_INFO(ProductionOrderEnum.SYSTEM_INFO),
    CREATOR_ID(ProductionOrderEnum.CREATOR_ID),
    ADD_TIME(ProductionOrderEnum.ADD_TIME),
    UPDATE_TIME(ProductionOrderEnum.UPDATE_TIME),

    STATUS(ProductionOrderEnum.STATUS),
    BOM_ID_LINK_TEXT(ProductionOrderEnum.BOM_ID_LINK_TEXT),
    INTO_WAREHOUSE_ID_LINK_TEXT(ProductionOrderEnum.INTO_WAREHOUSE_ID_LINK_TEXT),
    OUT_WAREHOUSE_ID_LINK_TEXT(ProductionOrderEnum.OUT_WAREHOUSE_ID_LINK_TEXT),
    COMPLETE_TIME(ProductionOrderEnum.COMPLETE_TIME),

    PRODUCT_NUM(ProductionOrderEnum.PRODUCT_NUM),
    PRODUCT_INSTOCK_NUM(ProductionOrderEnum.PRODUCT_INSTOCK_NUM),
    PRODUCT_UNINSTOCK_NUM(ProductionOrderEnum.PRODUCT_UNINSTOCK_NUM),
    INSTOCK_ID(ProductionOrderEnum.INSTOCK_ID),
    OUTSTOCK_ID(ProductionOrderEnum.OUTSTOCK_ID),
    ALL_INCOMING(ProductionOrderEnum.ALL_INCOMING),
    ALL_OUTBOUND(ProductionOrderEnum.ALL_OUTBOUND),
    HAS_RETURNED_MATERIEL(ProductionOrderEnum.HAS_RETURNED_MATERIEL),
    INSTOCK_ID_LINK_TEXT(ProductionOrderEnum.INSTOCK_ID_LINK_TEXT),
    OUTSTOCK_ID_LINK_TEXT(ProductionOrderEnum.OUTSTOCK_ID_LINK_TEXT),
    CLOSE_TIME(ProductionOrderEnum.CLOSE_TIME),
    PRODUCT_NAME(ProductionOrderEnum.PRODUCT_NAME),
    PRODUCT_NO(ProductionOrderEnum.PRODUCT_NO),
    PRODUCT_NAME_HIDE(ProductionOrderEnum.PRODUCT_NAME_HIDE),

    ;
    private ProductionOrderEnum anEnum;

    TempProductionOrderEnum(ProductionOrderEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempProductionOrderEnum> getAllEnum() {
        List<TempProductionOrderEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    /**
     * 初始化生产单编号流水号
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     * @author feng.zheng
     * @date 2019/1/18 14:09
     */
    public static void initSheetNo(FieldAttrEntity fieldAttrEntity) {
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.PRODUCTION_ORDER.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.PRODUCTION_ORDER.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(SHEET_NO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setSerialNumber(InitExplainsHelper.setSerialNumber(SerialNumberEnum.PRODUCTION_ORDER_NO));
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化执行时间
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initPlanTime(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setDateType("yyyy-MM-dd");
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化生产单状态
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     * @author feng.zheng
     * @date 2019/1/18 14:09
     */
    public static void initStatus(FieldAttrEntity fieldAttrEntity) {
//        ItemPoJo itemPoJo1 = new ItemPoJo();
//        itemPoJo1.setText(ProductionOrderStatusEnum.UNFINISHED.getAlias());
//        itemPoJo1.setValue(ProductionOrderStatusEnum.UNFINISHED.getCode());
//        ItemPoJo itemPoJo2 = new ItemPoJo();
//        itemPoJo2.setText(ProductionOrderStatusEnum.FINISHED.getAlias());
//        itemPoJo2.setValue(ProductionOrderStatusEnum.FINISHED.getCode());
//        ItemPoJo itemPoJo3 = new ItemPoJo();
//        itemPoJo3.setText(ProductionOrderStatusEnum.CLOSED.getAlias());
//        itemPoJo3.setValue(ProductionOrderStatusEnum.CLOSED.getCode());
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(ProductionOrderStatusEnum.class, fieldAttrEntity.getFieldType(),"alias",null));
    }

    /**
     * 初始化关联BOM清单
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initBomId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.BOMBILL.getCode());
        fieldAttrEntity.setLinkedText(BOM_ID_LINK_TEXT.anEnum.getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        saasParticularAttributePoJo.setRelyMode("bom");
        saasParticularAttributePoJo.setRelyType("base");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化关联入库仓库
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initIntoWarehouseId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.WAREHOUSE.getCode());
        fieldAttrEntity.setLinkedText(INTO_WAREHOUSE_ID_LINK_TEXT.anEnum.getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        saasParticularAttributePoJo.setRelyMode("bom");
        saasParticularAttributePoJo.setRelyType("relied");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化关联出库仓库
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initOutWarehouseId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.WAREHOUSE.getCode());
        fieldAttrEntity.setLinkedText(OUT_WAREHOUSE_ID_LINK_TEXT.anEnum.getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        saasParticularAttributePoJo.setRelyMode("bom");
        saasParticularAttributePoJo.setRelyType("relied");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化bom版本
     * 返回格式 {value: "m,,m", checked: 1}
     *
     * @param fieldAttrEntity 实体
     * @author feng.zheng
     * @date 2019/1/30 20:09
     */
    public static void initBomVersion(FieldAttrEntity fieldAttrEntity) {
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setRelyMode("bom");
        saasParticularAttributePoJo.setRelyType("relied");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setEditable(0);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultValue("请先关联BOM清单");
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_TYPE.getAlias()));
    }

    /**
     * 初始化成品产品
     *
     * @param fieldAttrEntity
     * @author feng.zheng
     * @date 2019/1/28 9:42
     */
    public static void initFinishedProduct(FieldAttrEntity fieldAttrEntity){
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setRelyMode("bom");
        saasParticularAttributePoJo.setRelyType("relied");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化成品产品子表单
     *
     * @param fieldAttrEntity
     * @author feng.zheng
     * @date 2019/1/28 9:42
     */
    public static void initMateriel(FieldAttrEntity fieldAttrEntity){
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setRelyMode("bom");
        saasParticularAttributePoJo.setRelyType("relied");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initProductName(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.PRODUCT.getCode());
        fieldAttrEntity.setLinkedText(PRODUCT_NAME_HIDE.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }

    /**
     * 负责人
     * @param fieldAttrEntity
     */
    public static void initOwnerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setMultiple(1);
        fieldAttrEntity.setRequired(1);
        //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增负责人，支持自定义；
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setUnableEditMemo(null);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.DYNAMIC.getAlias());
        defaultAttrPoJo.setDefaultValue(DefaultValueEnum.LOGIN_USER.getValue());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.PRODUCTION_MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.PRODUCTION_MANAGER));
    }

    public static void initCoUserId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setRequired(0);
        //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增协同人，支持自定义；
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setUnableEditMemo(null);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.PRODUCTION_MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.PRODUCTION_MANAGER));
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
}
